package code.netty.aio.client;

import code.netty.aio.ChannelAdapter;
import code.netty.aio.ChannelHandler;


import java.io.IOException;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.charset.Charset;
import java.util.Date;


/**
 * @author rocky
 */
public class AioClientHandler extends ChannelAdapter {

    public AioClientHandler(AsynchronousSocketChannel channel, Charset charset) {
        super(channel, charset);
    }

    @Override
    public void channelActive(ChannelHandler channelHandler) {
        try {
            System.out.println("AioClientHandler---channelActive:" + channelHandler.channel().getRemoteAddress());
            // 通知客户端链接成功
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void channelInActive(ChannelHandler channelHandler) {
    }

    @Override
    public void channelRead(ChannelHandler channelHandler, Object message) {
        System.out.println("AioClientHandler --> channelRead ：" + new Date() + " " + message + "\r\n");
        channelHandler.writeAndFlush("客户端信息处理Success！\r\n");
    }
}
